package com.panda.pfs.utils;

public class FileUtil {

    public static String withoutSuffixName(String fileName) {
        int index = fileName.lastIndexOf(".");
        if (index < 0) {
            return fileName;
        } else {
            return fileName.substring(0, index);
        }
    }

    public static String hashPath(String uuid) {
        StringBuilder path = new StringBuilder("/");
        for (int i = 0, k = 0 ; i < uuid.length() ; i ++) {
            if (isSafeWords(uuid.charAt(i))) {
                path.append(uuid.charAt(i));
                path.append("/");
                if (++k > 7) {
                    break;
                }
            }
        }
        return path.toString();
    }

    public static boolean isSafeWords(char c) {
        if (c >= '0' && c <= '9') {
            return true;
        }
        if (c >= 'a' && c <= 'z') {
            return true;
        }
        if (c >= 'A' && c <= 'Z') {
            return true;
        }
        return false;
    }
}
